package com.lixin.smartclassroom.ui.login

import android.annotation.SuppressLint
import com.drake.net.time.Interval
import com.drake.net.utils.scopeNetLife
import com.lixin.smartclassroom.R
import com.lixin.smartclassroom.api.beginimagelist
import com.lixin.smartclassroom.bean.BaseBeanDataList
import com.lixin.smartclassroom.bean.DataListBean
import com.lixin.smartclassroom.databinding.ActivityWelcomeBinding
import com.lixin.smartclassroom.ui.MainActivity
import com.lixinkeji.base.BaseActivity
import com.lixinkeji.extension.isFirstOpen
import com.lixinkeji.extension.isLogin
import com.lixinkeji.extension.load
import com.lixinkeji.extension.onClick
import com.lixinkeji.extension.start
import java.util.concurrent.TimeUnit

/**
 * Description 引导页
 * Author: lwc
 * Date:2024/1/2 16:22
 */
class WelcomeAct : BaseActivity<ActivityWelcomeBinding>() {
    override fun getViewBinding() = ActivityWelcomeBinding.inflate(layoutInflater)

    override fun topBarHide() = true
    override fun startPadding() = false

    private var interval: Interval? = null
    var imgList: ArrayList<DataListBean>? = null
    private var nowTime = 0

    @SuppressLint("UseCompatLoadingForDrawables")
    override fun iniView() {
        scopeNetLife {
            imgList = beginimagelist()
            binding.img.load(imgList?.get(0)?.imageurl!!)
            interval = Interval(
                0,
                1,
                TimeUnit.SECONDS,
                (imgList!!.size * 2).toLong()
            ).life(this@WelcomeAct)
            nowTime = imgList!!.size * 2
            interval!!.subscribe {
                if (it - 2 > 0) {
                    when (it.toString()) {
                        ((imgList!!.size - 1) * 2).toString() -> binding.img.load(imgList?.get(1)?.imageurl!!)
                        ((imgList!!.size - 2) * 2).toString() -> binding.img.load(imgList?.get(2)?.imageurl!!)
                    }
                }

            }.finish {
                goActivity()
            }.start()
        }

    }

    override fun onClick() {
        binding.apply {
            tvJump.onClick {
                interval?.reset()
                goActivity()

            }
        }
    }

    private fun goActivity() {
        if (isLogin)
            start(MainActivity::class.java)
        else
            start(LoginActivity::class.java)
        finish()
    }


}